# #!/usr/bin/python
# # -*- coding:utf-8 -*-
# 注册
import json
import string,random
# def check_username(username):
#     return set(username) & set(string.ascii_letters) and set(username) & set(string.digits)
# def check_password(password):
#     return set(password) & set(string.ascii_uppercase) and set(password) & set(string.ascii_lowercase) and \
#     set(password) & set(string.digits) and set(password) & set(string.punctuation)
count = 0
while count < 3:
    username_inp = input('请输入你的用户名：').strip()
    pwd_inp = input('请输入你的密码：').strip()
    re_pwd_inp = input('请再次输入密码：').strip()
    if 5<len(username_inp)<13 and (username_inp):
        if pwd_inp == re_pwd_inp\
                and 8<len(pwd_inp) < 13 \
                and len(set(pwd_inp) & set(string.ascii_uppercase)) > 0 \
                and len(set(pwd_inp) & set(string.ascii_lowercase)) > 0 \
                and len(set(pwd_inp) & set(string.digits)) > 0:
            print("可以了")
        else:
            print('两次输入的密码不一致')
            count += 1
            continue
    else:
        print("密码长度不合适")
            # count += 1
            # continue

    with open('user.txt','a+',encoding='utf8') as fa:
        fa.write(f'{username_inp}:{pwd_inp}\n')
        fa.flush()
        break
